﻿using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;

public static class DBUtils
{
    public static string ConnectionString
    {
        get
        {
            return WebConfigurationManager.ConnectionStrings["AlbumDBConnectionString"].ConnectionString;
        }   
    }

    public static IDbConnection CreateDBConnection()
    {
        return new SqlConnection(ConnectionString);
    }

    public static MediaDB CreateDataAbstaction()
    {
        return new MediaDB(ConnectionString);
//        if (_MediaDB == null)
//            _MediaDB = new MediaDB(ConnectionString);
//        return new SingletoneController<MediaDB>(_MediaDB);
    }

//    private static MediaDB _MediaDB;
}

//public class SingletoneController<TResource> : IDisposable
//{
//    public static implicit operator TResource(SingletoneController<TResource> s)
//    {
//        return s.Resource;
//    }
//
//    public SingletoneController(TResource obj)
//    {
//        Monitor.Enter(typeof(TResource));
//        _Resourse = obj;
//    }
//
//    public TResource Resource { get { return _Resourse; } }
//
//    public void Dispose()
//    {
//        Monitor.Exit(typeof(TResource));
//    }
//
//    private readonly TResource _Resourse;
//}
